package com.pctc.service.impl;

import com.pctc.dao.UserMapper;
import com.pctc.model.User;
import com.pctc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserMapper userMapper;



    @Override
    public List<User> findByName(String name) {
        if(!"".equals(name)&&name!=null) {
            System.out.println("edit1");
             System.out.println("edit2");
            return userMapper.findByName(name);
        }else
            return  null;
    }

    @Override
    public User findById(Integer id) {
        if (id!=null) {
            return userMapper.findById(id);
        }else
            return  null;
    }

    @Override
    public int insert(User user) {
        if (user!=null) {
            return userMapper.insert(user.getName(), user.getAge());
        }else{
            return  0;
        }
    }

    @Override
    public int updateUser(User user) {
        if (user!=null){
        return userMapper.updateUser(user);}
        else{
            return  0;
        }
    }

    @Override
    public int deleteUser(int id) {
        if (id>=0){
        return userMapper.deleteUser(id);}
        else{
            return 0;
        }
    }

    @Override
    public int countUser(int id) {
        if (id>=0){
        return userMapper.countUser(id);}
        else{
            return 0;
        }
    }
}
